/**
 * @file lib_emuc.h
 * @author circleup (circleup@foxmail.com)
 * @brief EMUC CAN SDK 头文件
 * @version 2.8
 * @date 2020-07-08
 * 
 * @copyright Copyright (c) 2020
 * 
 */

#ifndef __LIB_EMUC_H__
#define __LIB_EMUC_H__ 

/*------------------------------------------------------------------------------------------------------------*/
#define MAX_COM_PORT    16
#define MAX_BUF         512

#define ID_LEN          4
#define DATA_LEN        8   
#define VER_LEN         16

#define DIM(var, type)  (sizeof(var)) / sizeof(type)

#define BOOL    bool
#define TRUE    true
#define FALSE   false

/*------------------------------------------------------------------------------------------------------------*/
enum
{
    /* channel */
    EMUC_CH_1           = 1,
    EMUC_CH_2,
    EMUC_CH_BOTH,

    /* baudrate */
    EMUC_BAUDRATE_5K    = 0,
    EMUC_BAUDRATE_10K,
    EMUC_BAUDRATE_20K,
    EMUC_BAUDRATE_50K,
    EMUC_BAUDRATE_125K,
    EMUC_BAUDRATE_250K,
    EMUC_BAUDRATE_500K,
    EMUC_BAUDRATE_1M,
};

typedef struct
{
    int           com_port;

    int           channel;
    int           mod;
    int           rtr;
    int           dlc;

    unsigned char id[ID_LEN];
    unsigned char data[DATA_LEN];

} DATA_INFO;

typedef struct
{
    char fw[VER_LEN];
    char api[VER_LEN];
} VER_INFO;

/*------------------------------------------------------------------------------------------------------------*/
extern "C" int  EMUCOpenDevice(int port);
extern "C" void EMUCCloseDevice(int port);
extern "C" int  EMUCShowVer(int port, VER_INFO *ver);
extern "C" int  EMUCSetCAN(int port, int ch, int bdrate);
extern "C" int  EMUCReset(int port);
extern "C" int  EMUCReceive(DATA_INFO *info);
extern "C" int  EMUCSend(DATA_INFO *info);
extern "C" int  EMUCReceiveNonblock(DATA_INFO *info, int cnt, unsigned int interval);

#endif
